﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            // 设置窗体标题
            this.Text = "我的桌面app";
        }

        // 参数说明: sender-事件发送者, 如果是鼠标点击就是鼠标; e-事件的额外参数, 如鼠标点击的位置
        private void button1_Click(object sender, EventArgs e)
        {
            // 显示弹窗
            MessageBox.Show("hello world");
        }

        private void ShowNow(object sender, EventArgs e)
        {
            string nowDateStr = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            // 获取到引用并赋值
            this.timeField.Text = nowDateStr;
        }

        protected override void OnLayout(LayoutEventArgs levent)
        {
            // 1. 调用父类布局; 不是必须的
            base.OnLayout(levent);
            // 2. 获取窗口大小ClientSize(仅窗口区, 不含标题栏)
            int width = this.ClientSize.Width;
            int height = this.ClientSize.Height;

            // 3. 计算每一个控件的位置和大小
            int paddingWidth = 160;
            this.timeField.Size = new Size(width - paddingWidth, 21);
        }
    }
}
